package com.lagou.config.dao;

import com.lagou.common.zk.ConfigCenter;
import com.lagou.config.pojo.Resume;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

@Repository
public class ResumeDao {

    public List<Resume> findAll() throws Exception {

        List<Resume> resumes = new ArrayList<>();
        DataSource dataSource = ConfigCenter.getDataSource();

        try (Connection connection = dataSource.getConnection();
             Statement stmt = connection.createStatement();
             ResultSet rs = stmt.executeQuery("select * from tb_resume")) {

            while (rs.next()) {

                Resume resume = new Resume();
                resume.setId(rs.getLong("id"));
                resume.setName(rs.getString("name"));
                resume.setAddress(rs.getString("address"));
                resume.setPhone(rs.getString("phone"));

                resumes.add(resume);
            }
        }

        return resumes;
    }
}
